﻿/// <reference path="../../Scripts/commen_js/MJ_JSComment.js" />
function no_button() {
    $("#LoginBox_two").fadeOut("fast");
    $("#LoginBox_two").css({ display: 'none' });
}
function yes_button() {
    var type = manmanager.deleteid;
    var sql = "update manager set state='1' where id='"+type+"'";
    poststr = "{\"type\":\"manmanagerhandleoneexcute\",\"htmldata\":\"" + sql + "\"}";
    manmanager.postajaxs(poststr, manmanager.showdata);
}


var manmanager = {
    getdata: function (indexpage, indexwhere) {
        poststr = "{\"type\":\"manmanager\",\"pagecurrent\":\"" + indexpage + "\",\"indexwhere\":\"" + indexwhere + "\"}";
        this.postajaxs(poststr, this.showdata);
    },
    postajaxs: function (postdata, fangfa) {
        mj_ajax("../Handler1.ashx", "json", postdata, fangfa)
    },
    xuhao :1,
    change_color: 1,
    deleteid:1,
    changege_input : 1,
    showdata: function (data) {
        if (data.result == "ok") {
            $('#myClerk').modal('hide');
            $("#LoginBox_two").fadeOut("fast");
            $("#LoginBox_two").css({ display: 'none' });
        var record_count1 = data.record_count;
        record_count = record_count1 == 0 ? 1 : record_count1;
        var page_curent = data.page_curent;
        var datatable = data.table;
       
        var str = "";
        var table = document.getElementById("tbodyList");
        $("#tbodyList").empty();
        if (datatable.length != 0) {
            for (var i = 0; i < datatable.length; i++) {
                var tr = document.createElement("tr");
                if (manmanager.change_color % 2 == 0) {
                    tr.className = "bg-info";
                    manmanager.change_color++;
                }
                else {
                    manmanager.change_color++;
                }
                var td2 = document.createElement("td");
                td2.innerHTML = datatable[i].username;
                var td3 = document.createElement("td");
                td3.innerHTML = datatable[i].phone;
                var td4 = document.createElement("td");
                td4.innerHTML = datatable[i].createtime.replace("T", " ");
                var td5 = document.createElement("td");
                td5.id="small"
                var label2 = document.createElement("input");
                label2.id = datatable[i].id;
                label2.value = "删除";
                label2.setAttribute("type", "button");
                label2.className = "btn btn-default input2";
                label2.onclick = function () {
                    manmanager.delect(this.id);
                }
                td5.appendChild(label2);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                table.appendChild(tr);
            }
        }
        else {
            $("#tbodyList").empty();
        }
        //下面进行的是分页
        $("#record_shu").text(" 总记录数" + record_count1);
        if (record_count % 10 != 0) {
            page_shu = record_count / 10 + 1;
            page_shu = parseInt(page_shu)
        }
        else {
            page_shu = record_count / 10;
        }
        var options = {
            totalPages: page_shu,
            numberOfPages: 5,
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "第一页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "最后一页";
                    case "page":
                        return page;
                }
            },
            onPageClicked: function (event, originalEvent, type, page) {
                
                manmanager.getdata(page,"");
            }
        }
        $('#example').bootstrapPaginator(options);
   
    }

    else {
        layer.alert(data.msg, {
            icon: 1,
            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
        })
    }

    },
    search: function () {
        var state = $.trim($("#dateboxs").text());
        state = state == "全部" ? "" : state == "出售中" ? "0" : state == "已售完" ? "1" : state == "已下线" ? "2" : "";
        var keyword = $.trim($("#keyword").val());
        manmanager.getdata("1", state + "|" + keyword);
    },
    xiugai: function (id) {


    },

    savestaff: function () {
        var user = $("#user").val();
        var pwd =$.md5($("#pwd").val());
        var number = $("#num").val();
        var time = getNowFormatDate();
        if (isUndefinedNullOrEmpty(user)) {
            alert("用户名不能为空！");
            return;
        }
        else if (isUndefinedNullOrEmpty(pwd)) {
            alert("密码不能为空！");
            return;
        }
        var sql = "insert into manager (username,phone,user_type,password,createtime,state)"
        + " values('" + user + "','" + number + "','1','" + pwd + "','" + time + "','0')";
        poststr = "{\"type\":\"manmanagerhandleoneexcute\",\"htmldata\":\"" + sql + "\"}";
        manmanager.postajaxs(poststr, manmanager.showdata);
    },
    delect: function (id) {
        manmanager.deleteid = id;
        $("#content_two").text("确定删除管理员？");
        $("#LoginBox_two").fadeIn("fast");
        $("#LoginBox_two").css({ display: 'block' });

    },
};

